package com.distortiongames.level27.components
{
	import com.distortiongames.level27.GCam;
	import com.distortiongames.level27.math.Vector2D;
	import com.pblabs.core.PBComponent;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class CameraComponent extends PBComponent
	{
		private var _position:Vector2D = new Vector2D();
		
		public function get position() : Vector2D { 
			return _position;
		}
		
		public function set position(value:Vector2D) : void {
			_position = value;
			camera.to(_position.x, _position.y, 2, 0);
		}
		
		public var camera:GCam;
		
		[Inject]
		public var stage:Stage;
		
		[Inject]
		public var canvas:Sprite;
		
		override protected function onAdd():void
		{
			super.onAdd();
			camera = new GCam(canvas, canvas.getBounds(canvas));
			stage.addEventListener(Event.ENTER_FRAME, onFrame);
		}
		
		public function onFrame(e:*):void
		{
			applyBindings();
			
		}
		
		override protected function onRemove():void
		{
			super.onRemove();
		}
	
	}

}